<?                                                                                                                                                                                                                                                       
define ("ABSROOT", "/homepages/13/d97505132/htdocs/");                                                                                                                                                                                                   
define ("WEBROOT", "http://www.101stratford.com/");                                                                                                                                                                                                                                                       
define ("MAINTRANSFORMER", "/homepages/13/d97505132/htdocs/webservices/xsl/wsdl.xsl");                                                                                                                                                                                                                                       
define ("AJAXTRANSFORMER", "/homepages/13/d97505132/htdocs/webservices/xsl/ajax.xsl");                                                                                                                                                                                                                                       
define ("PHPCALLERTRANSFORMER", "/homepages/13/d97505132/htdocs/webservices/xsl/php_out.xsl");                                                                                                                                                                                                                              
define ("PHPLISTENERTRANSFORMER", "/homepages/13/d97505132/htdocs/webservices/xsl/php_in.xsl");                                                                                                                                                                                                                                       
define ("ASPLISTENERTRANSFORMER", "/homepages/13/d97505132/htdocs/webservices/xsl/asp_in.xsl");                                                                                                                                                                                                                                       
define ("ASPCALLERTRANSFORMER", "/homepages/13/d97505132/htdocs/webservices/xsl/asp_out.xsl");                                                                                                                                                                                                                                                       
define ("VBDOTNETTRANSFORMER", "/homepages/13/d97505132/htdocs/webservices/xsl/vb.xsl");                                                                                                                                                                                                                                                       
define ("VBSCRIPTTRANSFORMER", "/homepages/13/d97505132/htdocs/webservices/xsl/vbscript.xsl");                                                                                                                                                                                                                                       
define ("CSHARPTRANSFORMER", "/homepages/13/d97505132/htdocs/webservices/xsl/csharp.xsl");                                                                                                                                                                                                                                                       
        /*           

 "vb__invoke__"=>array("path"=>VBDOTNETTRANSFORMER,"name"=>"VB.NET","icon"=>"vbclass","type"=>"caller"),                                                                                                                                                                                                                                   
                          "csharp__invoke__"=>array("path"=>CSHARPTRANSFORMER,"name"=>"C#","icon"=>"csharpclass","type"=>"caller"),                                                                                    
                                     
*/          
  
                                                                                      
class wsdl                                                                                                                                                                                                                        
{                                                                                                                                                                                                                        
    var $m_document;                                                                                                                                                                                                     
    var $error_msg=NULL;                                                                                                                                                                                                                        
    var $content_type;                                                                                                                                                                                                                        
    var $operation;                                                                                                                                                                                                                        
    var $element;                                                                                                                                                                                                                        
    var $endpoint;                                                                                                                                                                                                                        
    var $namespace;                                                                                                                                                                                                                        
    var $m_address;                                                                                                                                                                                                                        
    var $m_wardrobe=array("ajax__invoke__"=>array("path"=>AJAXTRANSFORMER,"name"=>"Javascript","icon"=>"ajaxclass","type"=>"caller"),                                                                                                                                                                                                                                   
                          "vbscript__invoke__"=>array("path"=>VBSCRIPTTRANSFORMER,"name"=>"VBScript","icon"=>"vbscriptclass","type"=>"caller"),                                                                                                                                                                                                                                   
                          "asp__invoke__"=>array("path"=>ASPLISTENERTRANSFORMER,"name"=>"ASP","icon"=>"aspclass","type"=>"listener"),                                                                                    
                          "asp_out__invoke__"=>array("path"=>ASPCALLERTRANSFORMER,"name"=>"ASP","icon"=>"asp_outclass","type"=>"caller"),                                                                                    
                          "php__invoke__"=>array("path"=>PHPLISTENERTRANSFORMER,"name"=>"PHP","icon"=>"phpclass","type"=>"listener"),                                                                                    
                          "php_out__invoke__"=>array("path"=>PHPCALLERTRANSFORMER,"name"=>"PHP","icon"=>"php_outclass","type"=>"caller")                                                                                    
                         );                                                                                                                                                                        
 
    var $m_xmlns=array("xmlns:http"=>"http://schemas.xmlsoap.org/wsdl/http/",                                                                                                                                                                       
                       "xmlns:soap"=>"http://schemas.xmlsoap.org/wsdl/soap/",                                                                                                                                                                       
                       "xmlns:s"=>"http://www.w3.org/2001/XMLSchema",                                                                                                                                                                       
                       "xmlns:soapenc"=>"http://schemas.xmlsoap.org/soap/encoding/",                                                                                                                                                                       
                       "xmlns:tm"=>"http://microsoft.com/wsdl/mime/textMatching/",                                                                                                                                                                       
                       "xmlns:mime"=>"http://schemas.xmlsoap.org/wsdl/mime/",                                                                                                                                                                       
                       "xmlns"=>"http://schemas.xmlsoap.org/wsdl/" );                                                                                                                                                                        
    var $m_port_type=array ("Soap"=>array("transport"=>"http://schemas.xmlsoap.org/soap/http","style"=>"document"),                                                                                                                                                                
                            "HttpGet"=>array("verb"=>"GET"),                                                                                                                                                                
                            "HttpPost"=>array("verb"=>"POST"));                                                                                                                                                             
                                                                                                                                                                                              
    var $m_prefix="s0";                                                                                                                                                                      
                                                                                                                                                                                                        
    function wsdl ($address="")                                                                                                                                                                                                                        
    {                                                                                                                                                                                                                        
        $this->m_address=$address;                                                                                                                                                                                                                        
        $this->content_type="text/html";                                                                                                                                                                                                                        
    }                                                                                                                                                                                                                        

    function save_webservice($classname,$endpoint,$namespace, $prefix="s0")                                                                                                                                                                                                                        
    {                                                                                                                                                                                                                                                                      
        if (! ( $doc = domxml_open_file( ABSROOT . $this->m_address ) ) )                                                                                                                                                                                                                                                                                                                                                 
        {                                                                                                                                                                                                           
            $doc=domxml_new_doc("1.0");                                                                                                                                                                   
             # create DEFINITIONS element                                                                                                      
            $m_prefix=$prefix;                                                                                                                                                                    
            $definitions=$doc->create_element ("definitions");                                                                                                                                                                    
            while (list ($name,$value)=each ($this->m_xmlns))                                                                                                                                                                    
            {                                                                                                                                                                    
                $definitions->set_attribute ($name, $value);                                                                                                                                                                     
            }                                                                                                                    
                                                                                                                                                                                  
            $definitions->set_attribute ("xmlns:" . $this->m_prefix, $namespace);                                                                                                                        
            $definitions->set_attribute ("targetNamespace", $namespace);                                                                                                                                                                
            $doc->append_child ($definitions);                                                                                                                                                              
                                                                                                                                                                                        
            # create DEFINITIONS/TYPES element                                                                                                                                                                                                                    
            $types=$doc->create_element ("types");                                                                                                                                                                      
            $definitions->append_child ($types);                                                                                                                                                                    

            # create DEFINITIONS/SCHEMA element                                                                                                                                                                                                                      
            $schema=$doc->create_element ("s:schema");                                                                                                                                                                     
            $schema->set_attribute ("elementFormDefault", "qualified");                                                                                                                                                                    
            $schema->set_attribute ("targetNamespace", $namespace);                                                                                                                                                                   
            $types->append_child ($schema);                                                                                                                                                                  
                                                                                                                                                                                                                
            $port_types=array();                                                                                                                                                                     
            $ports=array();                                                                                                                                                                     
            $bindings=array();                                                                                                                                                                     
            while (list ($name,$value)=each ($this->m_port_type))                                                                                                                                                                    
            {                                                                                                                                                                    
                # create DEFINITIONS/SERVICE/PORT elements                                                                                                                                                                 
                $port=$doc->create_element ("port");                                                                                                                                                                   
                $port->set_attribute ("name", $classname . $name);                                                                                                                                                               
                $port->set_attribute ("binding", $this->m_prefix . ":" . $classname . $name);                                                                                                                                                              

                # create DEFINITIONS/SERVICE/PORT/ADDRESS element                                                                                                                                                              
                $address=$doc->create_element (($name=="Soap" ? "soap" : "http") . ":address");                                                                                                                                                                 
                $address->set_attribute ("location", $endpoint);                                                                                                                                                                
                $port->append_child ($address);                                                                                                                                                              

                # create DEFINITIONS/PORTTYPE elements                                                                                                                                                                 
                $port_type=$doc->create_element ("portType");                                                                                                                                                                   
                $port_type->set_attribute ("name", $classname . $name);                                                                                                                                                                  
                                                                                                                                                                
                # create DEFINITIONS/BINDING elements                                                                                                                                                                                                              
                $binding=$doc->create_element ("binding");                                                                                                                                                               
                $binding->set_attribute ("name", $classname . $name);                                                                                                                                                                  
                $binding->set_attribute ("type", $this->m_prefix . ":" . $classname . $name);                                                                                                                                                                  
                $binding_child=$doc->create_element (($name=="Soap" ? "soap" : "http") . ":binding");                                                                                                                                                                    
                while (list ($child_name,$child_value)=each ($value))                                                                                                                                                                    
                {                                                                                                                                                               
                     $binding_child->set_attribute ($child_name, $child_value);                                                                                                                                                               
                }                                                                                                                                                               
                $binding->append_child ($binding_child);                                                                                                                                                               

                $ports[]=$port;                                                                                                                                                               
                $port_types[]=$port_type;                                                                                                                                                              
                $bindings[]=$binding;                                                                                                                                                               
            }                                                                                                                                                                           
                                                                                                                                                                            
            foreach ($port_types as $port_type) $definitions->append_child ($port_type);                                                                                                                                                               
            foreach ($bindings as $binding) $definitions->append_child ($binding);                                                                                                                                                               

            # create DEFINITIONS/SERVICE elements                                                                                                                                                                                                                
            $service=$doc->create_element ("service");                                                                                                                                                                
            $service->set_attribute ("name", $classname);                                                                                                                                                                 
            $definitions->append_child ($service);                                                                                                                                                                 


            foreach ($ports as $port) $service->append_child ($port);                                                                                                                                                               
            $this->m_address="webservices/wsdl/" . $classname . ".wsdl";                                                                                                                                                                                                                          
        }                                                                                                                                                             
        else                                                       
        {                                                                                                
            $query_binding="//*[local-name()='binding']";                                                                                                                                                                                                 
            $x_binding= select_single_node ($doc, $query_binding);                                                                                                                                                           
            if (! $x_binding )                                                                                                                                                       
            {                                                                                                                                                                               
                    $this->error_msg = "Binding was not found";                                                                                                                                                                                              
                    return false;                                                                                                  
            }                                                                                                       
            $this->m_prefix=explode(':', $x_binding->get_attribute("type"));                                                                                                                                                   
            $this->m_prefix=$this->m_prefix[0];                                                       

        }                                                       
        # set modifiable values                                                                                                                                                                             
        $query_definitions= "//*[local-name()='definitions']";                                                                                                                                                            
        $query_schema= "//*[local-name()='schema']";                                                                                                                                                            
        $query_address= "//*[local-name()='port']/*[local-name()='address']";                                                                                                                                                                                                
        $x_definitions= select_single_node ($doc, $query_definitions);                                                           
        $x_address= select_nodes ($doc, $query_address);                                                                                                                                                               
        foreach ($x_address as $address)                                                                                                                                                              
        {                                                                                                                                                            
            $address->set_attribute ("location", $endpoint);                                                                                                                                                                   
        }                                                                                                                                                                                          
        $doc->dump_file ( ABSROOT . $this->m_address , false, true);                                                                                                                                                                                           
        return true;                                                                                                                                                                                     
    }                                                                                                                                                                                                                        

    function save_method($methodname,$datatype="s:string",$is_array=NULL)                                                                                                                                                                                                                        
    {                                                                                                                                                                                                                                                                     
        if ($dom = domxml_open_file( ABSROOT . $this->m_address ))                                                                                                                                                                                                                                                                                                                                                 
        {                                                                                                                                                                
            $query_binding="//*[local-name()='binding']";                                                                                                                                                       
            $query_definitions="//*[local-name()='definitions']";                                                                                                                                                       
            $query_schema="//*[local-name()='schema']";                                                                                                                                                       
            $query_method="//*[local-name()='element'][@name='" . $methodname . "']";                                                                                                                                                                                                   
            $x_binding= select_single_node ($dom, $query_binding);                                                                                                                                                           
            if (! $x_binding )                                                                                                                                                       
            {                                                                                                                                                                               
                    $this->error_msg = "Binding was not found";                                                                                                                                                                                              
                    return false;                                                                                                  
            }                                                                                                       
            $this->m_prefix=explode(':', $x_binding->get_attribute("type"));                                                                                                                                                   
            $this->m_prefix=$this->m_prefix[0];                                                                                                                                                   
            $x_schema= select_single_node ($dom, $query_schema);                                                                                                                                                          
            $x_method= select_single_node ($dom, $query_method);                                                                                                                                                          
            $x_definitions= select_single_node ($dom, $query_definitions);                                                                                                                                                          
            if (! $x_method )                                                                                                                                                       
            {                                                                                                                                                       
                # create ELEMENT element for the method                                                                                                                                                                                                                                                     
                $x_method=$dom->create_element ("s:element");                                                                                                                                                       
                $x_method->set_attribute ("name", $methodname);                                                                                                                                                        
                $x_complex=$dom->create_element ("s:complexType");                                                                                                                                                                                              
                $x_method->append_child ($x_complex);                                                                                                                                                       
                $x_schema->append_child ($x_method);                                                                                                                                                        

                # create ELEMENT element for the method response                                                                                                                                                                                                                                                
                $x_response=$dom->create_element ("s:element");                                                                                                                                                      
                $x_response->set_attribute ("name", $methodname . "Response");                                                                                                                                                      
                $x_complex=$dom->create_element ("s:complexType");                                                                                                                                                                                              
                $x_sequence=$dom->create_element ("s:sequence");                                                                                                                                                                                              
                $x_complex->append_child ($x_sequence);                                                                                                                                                                                              
                $x_response->append_child ($x_complex);                                                                                                                                                        
                $x_schema->append_child ($x_response);                                                                                                                                                    
                                                                                                                                                                                                                                                                                    
                # create ELEMENT element for the method response data type                                                                                                                                                                                                                                               
                $x_datatype=$dom->create_element ("s:element");                                                                                                                                                                                             
                $x_datatype->set_attribute ("minOccurs", "0");                                                                                                                                                       
                $x_datatype->set_attribute ("maxOccurs", $is_array ? "unbounded" : "1");                                                                                                                                                                                              
                $x_datatype->set_attribute ("name", $methodname . "Result");                                                                                                                                                                                              
                $x_datatype->set_attribute ("type", $datatype);                                                                                                                                                                                             
                $x_sequence->append_child ($x_datatype);                                                                                                                                                      
                                                                                                                                                               
                                                                                                                                                                                    
                $messages=array();                                                                                                                                                                   
                $port_types=array();                                                                                                                                                                     
                $bindings=array();                                                                                                                                                                     
                while (list ($name,$value)=each ($this->m_port_type))                                                                                                                                                                    
                {                                                                                                                                                        
                                                                                                                                                      
                    # create MESSAGE elements                                                                                                                                                          
                    $message=$dom->create_element ("message");                                                                                                                                                                   
                    $message->set_attribute ("name", $methodname . $name . "In");                                                                                                                                                      
                    if ($name=="Soap")                                                                                                                                                     
                    {                                                                                                                                                     
                        $part=$dom->create_element ("part");                                                                                                                                                     
                        $part->set_attribute ("name", "parameters");                                                                                                                                                     
                        $part->set_attribute ("element", $this->m_prefix . ":" . $methodname);                                                                                                                                                     
                        $message->append_child ($part);                                                                                                                                                    
                    }                                                                                                                                                       
                    $messages[]=$message;                                                                                                                                                               
                    $message=$dom->create_element ("message");                                                                                                                                                                   
                    $message->set_attribute ("name", $methodname . $name . "Out");                                                                                                                                                      
                    $part=$dom->create_element ("part");                                                                                                                                                    
                    if ($name=="Soap")                                                                                                                                                     
                    {                                                                                                                                                         
                        $part->set_attribute ("name", "parameters");                                                                                                                                                     
                        $part->set_attribute ("element", $this->m_prefix . ":" . $methodname . "Response");                                                                                                                                                     
                    }                                                                                                                                                      
                    else                                                                                                                                                    
                    {                                                                                                                                                    
                        $part->set_attribute ("name", "Body");                                                                                                                                                                                      
                        $part->set_attribute ("element", $datatype);                                                                                                                                                       
                    }                                                                                                                                                     
                    $message->append_child ($part);                                                                                                                                                    
                    $messages[]=$message;                                                                                                                                                    

                                                                                                                                                                       
                    # create PORTTYPE/OPERATION elements                                                                                                                                                    
                    $operation=$dom->create_element ("operation");                                                                                                                                                   
                    $input=$dom->create_element ("input");                                                                                                                                                   
                    $output=$dom->create_element ("output");                                                                                                                                                   
                    $operation->set_attribute ("name", $methodname);                                                                                                                                                   
                    $input->set_attribute ("message", $this->m_prefix . ":" . $methodname . $name . "In");                                                                                                                                                   
                    $output->set_attribute ("message", $this->m_prefix . ":" . $methodname . $name . "Out");                                                                                                                                                   
                    $operation->append_child ($input);  # PORTTYPE/OPERATION/INPUT                                                                                                                                                 
                    $operation->append_child ($output); # PORTTYPE/OPERATION/OUTPUT                                                                                                                                               
                    $port_types[$name]=$operation;                                                                                                                                                  

                    # create BINDING/OPERATION elements                                                                                                                                                     
                    $operation=$dom->create_element ("operation");                                                                                                                                                 
                    $sub_operation=$dom->create_element (($name=="Soap" ? "soap" : "http") . ":operation");                                                                                                                                                   
                    $input=$dom->create_element ("input");                                                                                                                                                   
                    $output=$dom->create_element ("output");                                                                                                                                                 
                    if ($name=="Soap")                                                                                                                                                 
                    {                                                                                                                                                 
                        $sub_operation->set_attribute ("soapAction", $this->namespace . "/" . $methodname);                                                                                                                                                 
                        $sub_operation->set_attribute ("style", "document");                                                                                                                                                    
                        $sub_input=$dom->create_element ("soap:body");                                                                                                                                                 
                        $sub_input->set_attribute ("use", "literal");                                                                                                                                                    
                        $sub_output=$sub_input->clone_node (true);                                                                                                                                                   
                    }                                                                                                                                                 
                    else                                                                                                                                                  
                    {                                                                                                                                                 
                        $sub_operation->set_attribute ("location", "/" . $methodname);                                                                                                                                                      
                        $sub_input=$dom->create_element ($name=="HttpGet" ? "http:urlEncoded" : "mime:content");                                                                                                                                                 
                        $sub_output=$dom->create_element ("mime:mimeXml");                                                                                                                                                   
                        $sub_output->set_attribute ("part", "Body");                                                                                                                                                
                        if ($name=="HttpPost") $sub_input->set_attribute ("type", "application/x-www-form-urlencoded");                                                                                                                                                 
                    }                                                                                                                                                   
                    $operation->set_attribute ("name", $methodname);                                                                                                                                                      
                    $input->append_child ($sub_input);                                                                                                                                                   
                    $output->append_child ($sub_output);                                                                                                                                                   
                    $operation->append_child ($sub_operation);                                                                                                                                                   
                    $operation->append_child ($input);                                                                                                                                                   
                    $operation->append_child ($output);                                                                                                                                                   
                    $bindings[$name]=$operation;                                                                                                                                                   
                                                                                                                                                                       
                }                                                                                                                                                  
                                                                                                                                                                                     
                $x_service= select_single_node ($dom, "//*[local-name()='service']");                                                                                                                                                 
                $classname=$x_service->get_attribute ("name");                                                                                                                                                          
                while (list ($name,$value)=each ($port_types))                                                                                                                                                                    
                {                                                                                                                                                   
                    $port_type = select_single_node ($dom, "//*[local-name()='portType'][@name='" . $classname . $name . "']");                                                                                                                                                  
                    if ($port_type) $port_type->append_child ($value);                                                                                                                                               
                }                                                                                                                                                 
                while (list ($name,$value)=each ($bindings))                                                                                                                                                                    
                {                                                                                                                                                   
                    $binding = select_single_node ($dom, "//*[local-name()='binding'][@name='" . $classname . $name . "']");                                                                                                                                                  
                    if ($binding ) $binding->append_child ($value);                                                                                                                                               
                }                                                                                                           
                $port_type = select_single_node ($dom, "//*[local-name()='portType']");                                                                                                                                                  
                foreach ($messages as $message) $message->insert_before ($message, $port_type);                                                                                                                                                
            }                                                                                                               

            $query_datatype = "//*[local-name()='element'][@name='" . $methodname . "Response']";                                                                                                                                    
            $query_datatype.= "/*[local-name()='complexType']/*[local-name()='sequence']/*[local-name()='element']";                                                                                                              
            $x_datatype= select_single_node ($dom, $query_datatype);                                                                                                                                                                                                 
                                                                                                                                                                                                                 
            if ($x_datatype)                                                                                                                                                                                                   
            {                                                                                                                                                
                $x_datatype->set_attribute ("maxOccurs", $is_array ? "unbounded" : "1");                                                                                                                                                                                              
                $x_datatype->set_attribute ("type", $datatype);                                                                                                                                                                                      
            }                                                                                                                             

            // TO DO: write code to change modifiable properties                                                                                                                                                                              
            $dom->dump_file ( ABSROOT . $this->m_address, false, true);                                                                                                                                                                                           
            return true;                                                                                                                                                    
        }                                                                                                                                                                                                        
    }                                                                                                                                                                                                                        

    function safe_delete($dom, $query, $error)                                                                                                                                                                                                                        
    {                                                                                                                              
        $x_query = select_single_node ($dom, $query);                                                                                                                                                                                                         
        if (! $x_query)                                                                                                                                                                                                     
        {                                                                                                                                                                                             
            $this->error_msg = $error;                                                                                                                                                                                              
            return false;                                                                                                                                                                                              
        }                                                                                                                                                                                                           
        $x_query->unlink_node();                                                                                                                      
        return true;                                                                                                                                                                                                   
    }                                                                                                                                                                                                                        

    function remove_method($methodname)                                                                                                                                                                                                                        
    {                                                                                                                                                                                                                        
        if (! ($dom = domxml_open_file( ABSROOT . $this->m_address ) ))                                                                                                                                                                                                                                                                                                                                                 
        {                                                                                                                                                                               
            $this->error_msg = "File " . $this->m_address . " was not found";                                                                                                                                                                                              
            return false;                                                                                                                                                                                                                               
        }                                                                                                                                                                                                         
        $query_method   = "//*[local-name()='element'][@name='" . $methodname . "']";                                                                                                                                                                                               
        $query_response = "//*[local-name()='element'][@name='" . $methodname . "Response']";                                                                                                                     
        if ( $this->safe_delete ($dom, $query_method, "Method $methodname was not found") )                                                                                                                    
        {                                                                                                                    
            if ( $this->safe_delete ($dom, $query_response, "Response Method for $methodname was not found") )                                                                                                                    
            {                                                                                                                                                                    
                while (list ($name,$value)=each ($this->m_port_type))                                                                                                                                                                    
                {                                                                                                                    
                    $query_message_in="//*[local-name()='message'][@name='" . $methodname . $name . "In']";                                                                                                                    
                    if ( $this->safe_delete ($dom, $query_message_in, "Message IN element for $methodname $name was not found") )                                                                                                                    
                    {                                                                                                                    
                        $query_message_out="//*[local-name()='message'][@name='" . $methodname . $name . "Out']";                                                                                                                    
                        if ( ! $this->safe_delete ($dom, $query_message_out, "Message OUT element for $methodname $name was not found") )                                                                                                                    
                        {                                                                                                                    
                            return false;                                                                                                                    
                        }                                                                                                                     
                    }  else return false;                                                                                                                    
                }                                                                                                                    
                foreach( select_nodes ($dom, "//*[local-name()='operation'][@name='" . $methodname . "']") as $x_method)                                                                                                                    
                {                                                                                                                    
                   $x_method->unlink_node();                                                                                                                    
                }                                                                                                                    
            } else return false;                                                                                                                    
        } else return false;                                                                                                                                                                                                        
                                                                                                                            
                                                                                                                                                                                              
        $dom->dump_file ( ABSROOT . $this->m_address , false, true);                                                                                                                                                                                               
        return true;                                                                                                                                                                                                                    
    }                                                                                                                                                                                                                        

    function save_param($methodname,$paramname,$datatype="s:string",$is_array=NULL)                                                                                                                                                                                                                        
    {                                                                                                                                                                                                                                                                      
        if ($dom = domxml_open_file( ABSROOT . $this->m_address ))                                                                                                                                                                                                                                                                                                                                                 
        {                                                                                                                                                                                                           
            $query_method   = "//*[local-name()='element'][@name='" . $methodname . "']";                                                                                                                                                                                               
            $query_complex  = $query_method . "/*[local-name()='complexType']";                                                                                                                                                                                 
            $query_sequence = $query_complex . "/*[local-name()='sequence']";                                                                                                                                                                                               
            $query_element  = $query_sequence . "/*[local-name()='element'][@name='" . $paramname . "']";                                                                                                                                                                                               
            $x_element = select_single_node ($dom, $query_element);                                                                                                                                                                                                         
            if (! $x_element)                                                                                                                                                                                                     
            {                                                                                                                                                                                                          
                $x_method = select_single_node ($dom, $query_method);                                                                                                                                                                                                   
                if (! $x_method )                                                                                                                                                                                                   
                {                                                                                                                                                                                              
                    $this->error_msg = "Method $methodname was not found";                                                                                                                                                                                              
                    return false;                                                                                                                                                                                              
                }                                                                                                                                                                                              
                $x_complex = select_single_node ($dom, $query_complex);                                                                                                                                                                                                   
                if (! $x_complex )                                                                                                                                                                                                   
                {                                                                                                                                                                                              
                    $x_complex=$dom->create_element ("s:complexType");                                                                                                                                                                                              
                    $x_method->append_child ($x_complex);                                                                                                                                                                                           
                }                                                                                                                                                                                               
                $x_sequence = select_single_node ($dom, $query_sequence);                                                                                                                                                                                                   
                if (! $x_sequence )                                                                                                                                                                                                   
                {                                                                                                                                                                                              
                    $x_sequence=$dom->create_element ("s:sequence");                                                                                                                                                                                              
                    $x_complex->append_child ($x_sequence);                                                                                                                                                                                           
                }                                                                                                                                                                                             
                                                                                                                                                                                                              
                $x_element=$dom->create_element ("s:element");                                                                                                                                                                                              
                $x_element->set_attribute ("name", $paramname);                                                                                                                                                                                              
                $x_element->set_attribute ("minOccurs", "0");                                                                                                                                                                                                 
                $x_sequence->append_child ($x_element);                                                                                                                                                                                               
            }                                                                                                                                                                                                           
            $x_element->set_attribute ("maxOccurs", $is_array ? "unbounded" : "1");                                                                                                                                                                                              
            $x_element->set_attribute ("type", $datatype);                                                                                                                                                                                             
            $dom->dump_file ( ABSROOT . $this->m_address , false, true);                                                                                                                                                                                           
            return true;                                                                                                                                                                                                                              
        }                                                                                                                                                                                                                    
    }                                                                                                                                                                                                                        

    function remove_param($methodname,$paramname)                                                                                                                                                                                                                        
    {                                                                                                                                                                 
        if ( ! $this->load_dom() ) return false;                                                                                                                                                                                                                                                                                  
        $query_element  = "//*[local-name()='element'][@name='" . $methodname . "']";                                                                                                                                                                                               
        $query_element .= "/*[local-name()='complexType']/*[local-name()='sequence']";                                                                                                                                                                                               
        $query_element .= "/*[local-name()='element'][@name='" . $paramname . "']";                                    
        if ( ! $this->safe_delete ($this->m_document, $query_element, "Element $paramname was not found") )                                                                                                                                                                                             
        {                                                                                                                                                                                             
            return false;                                                                                                                                                                                              
        }                                                                                                                                                                                                           
        $this->m_document->dump_file ( ABSROOT . $this->m_address , false, true);                                                                                                                                                                                               
        return true;                                                                                                                                                                                                               
    }                                                                                                                                                                                                                        

    function save_datatype($typename, $complex=NULL)                                                                                                                                                                                                                        
    {                                                                                                                                                                                
        if ( ! $this->load_dom() ) return false;                                     
        $nodename       = ($complex ? "complex" : "simple") . "Type";                                                                                                                                                           
        $childname      = "s:" . ($complex ? "sequence" : "restriction");                                                                                                                                                           
        $query_schema   = "//*[local-name()='schema']";                                                                                                                                                       
        $x_schema       = select_single_node ($this->m_document, $query_schema);                                                                                                                                                           
        if (! $x_schema )                                                                                                                                                       
        {                                                                                                                                                                               
             $this->error_msg = "Schema element was not found";                                                                                                                                                                                              
             return false;                                                                                                  
        }                                                                                                                                                                                                                                            
        $query_element  = "//*[local-name()='" . $nodename . "'][@name='" . $typename . "']";                                                                                                                                                                                                 
        $x_element = select_single_node ($this->m_document, $query_element);                                                                                                                                                                                                         
        if (! $x_element)                                                                                                                                                                                                     
        {                                                                                                                                                                          
            $x_element=$this->m_document->create_element ("s:" . $nodename);                                                                                                                                                                                              
            $x_element->set_attribute ("name", $typename);                                                                                                                                                                                              
            $x_schema->append_child ($x_element);                                                                                                                              
            $x_child=$this->m_document->create_element ($childname);                                                                                                                                                                                              
            if (!$complex) $x_child->set_attribute ("base", "s:string");                                                                                                                                                                                              
            $x_element->append_child ($x_child);                                  
        }                                                                                                                                                                                                 
        $this->m_document->dump_file ( ABSROOT . $this->m_address , false, true);                                                                                                                                                                                               
        return true;                                                                                                                                                                                           
    }                                                                                                                                                                                                                        

    function remove_datatype($typename)                                                                                                                                                                                                                        
    {                                                                                                                                                                                
        if ( ! $this->load_dom() ) return false;                                                                                                                                                                                                                                                                                     
        $query_complex = "//*[local-name()='complexType'][@name='" . $typename . "']/*[local-name()='sequence']";                                    
        $query_simple  = "//*[local-name()='simpleType'][@name='" . $typename . "']/*[local-name()='restriction']";                                    
        if ( ! $this->safe_delete ($this->m_document, $query_complex, "Element $typename was not found") )                                                                                                                                                                                             
        {                                                                                                                                                                                             
            if ( ! $this->safe_delete ($this->m_document, $query_simple, "Element $typename was not found") )                                                                                                                                                                                             
            {                                                                                                                                                                                             
                return false;                                                                                                                                                                                              
            }                                                                                                                                                                                                           
        }                                                                                                                                                                                                           
        $this->m_document->dump_file ( ABSROOT . $this->m_address , false, true);                                                                                                                                                                                               
        return true;                                                                                                                                                                                                         
    }                                                                                                                                                                                                                        

    function save_datamember($typename, $membername, $datatype=NULL, $isarray=NULL)                                                                                                                                                                                                                        
    {                                                                                                                                                                                 
        if ( ! $this->load_dom() ) return false;                                                                                                                                                                                                                                                       
        $query_complex = "//*[local-name()='complexType'][@name='" . $typename . "']";                                    
        $query_simple  = "//*[local-name()='simpleType'][@name='" . $typename . "']";                                       
        $node_name     = "complexType";                                                                                                                                                                                          
        $child_name    = "element";                                                                                                                                                                                          
        $child_attr    = array ("name"=>$membername,"type"=>$datatype,"minOccurs"=>"0","maxOccurs"=>($isarray?"unbounded":"1") );                                                                                                                                                                                          
        $x_element     = select_single_node ($this->m_document, $query_complex);                                                                                                                                                                                                             
        if (! $x_element)                                                                                                                                                                                                     
        {                                                                                                                                                                          
            $x_element = select_single_node ($this->m_document, $query_simple);                                                                                                                                                                                                            
            if (! $x_element)                                                                                                                                                                                                     
            {                                                                                                                                                                   
                $this->error_msg = "Type element was not found";                                                                                                                                                                                              
                return false;                                  
            }                                           
            $node_name  = "simpleType";                                                                                                                                                                                          
            $child_name = "enumeration";                                                                                                                                                                                          
            $child_attr = array ("value"=>$membername);                                                                                                     
        }                                                                                                                                                                                                                        
        $query_member  = "//*[local-name()='" . $node_name ."'][@name='" . $typename . "']/*";                                                                                                                                                                                          
        $x_member      = select_single_node ($this->m_document, $query_member);                                                                                                                                                                                                            
        if (!$x_member)                                                                                                                                                                                                     
        {                                                                                                                                                     
            $this->error_msg = "Member " . $typename . " was not found";                                                                                                                                                                                              
            return false;                             
        }                                                                                                                                                
        $query_type    = $query_member . "/*[local-name()='" . $child_name ."'][@name='" . $membername . "']";                                                                                                                                                
        $x_type        = select_single_node ($this->m_document, $query_type);                                                                                                                                                                                                            
        if ($x_type)                                                                                                                                                                                                     
        {                                                                                                                                                     
            $this->error_msg = "Member " . $membername . " already exists";                                                                                                                                                                                              
            return false;                             
        }                                                                                                                                                
        $x_child=$this->m_document->create_element("s:" . $child_name);                              
        while (list($name,$value)=each($child_attr)) $x_child->set_attribute ($name, $value);                                                                                                                                                                                            
        $x_member->append_child ($x_child);                                                                                                                                                                                                                                           
        $this->m_document->dump_file ( ABSROOT . $this->m_address, false, true);                                                                                                                                                                                               
        return true;                                                                                                                                                                                 
    }                                                                                                                                                                                                                       

    function remove_datamember($typename, $membername)                                                                                                                                                                                                                        
    {                                                                                                                                                                                                                      
        if ( ! $this->load_dom() ) return false;                                                                                                                                                                                                                       
        $query_complex = "//*[local-name()='complexType'][@name='" . $typename . "']";                                    
        $query_simple  = "//*[local-name()='simpleType'][@name='" . $typename . "']";                                       
        $node_name     = "complexType";                                                                                                                                                                                          
        $child_name    = "element";                                                                                                                                                                                          
        $x_element     = select_single_node ($this->m_document, $query_complex);                                                                                                                                                                                                             
        if (! $x_element)                                                                                                                                                                                                     
        {                                                                                                                                                                          
            $x_element = select_single_node ($this->m_document, $query_simple);                                                                                                                                                                                                            
            if (! $x_element)                                                                                                                                                                                                     
            {                                                                                                                                                                   
                $this->error_msg = "Type element was not found";                                                                                                                                                                                              
                return false;                                  
            }                                           
            $node_name  = "simpleType";                                                                                                                                                                                          
            $child_name = "enumeration";                                                                                                                                                                                          
        }                                                                                                                                                                                                                           
        $query_member  = "//*[local-name()='" . $node_name ."'][@name='" . $typename . "']/*";                                                                                                                                                                                          
        $query_type    = $query_member . "/*[local-name()='" . $child_name ."'][@name='" . $membername . "']";                                 
        if ( ! $this->safe_delete ($this->m_document, $query_type, "Element $membername was not found") )                                                                                                                                                                                             
        {                                                                                                                                                                                             
            return false;                                                                                                                                                                                              
        }                                                                                                                                                                                                           
        $this->m_document->dump_file ( ABSROOT . $this->m_address , false, true);                                                                                                                                                                                               
        return true;                                                                                                                                                                             
    }                                                                                                                                                                                                                        

    function load_dom()                                 
    {                                                                                                                                                                                                                 
        if (! ($this->m_document = domxml_open_file( ABSROOT . $this->m_address ) ))                                                                                                                                                                                                                                                                                                                                                 
        {                                                                                                                                                                               
            $this->error_msg = "File " . $this->m_address . " was not found";                                                                                                                                                                                              
            return false;                                                                                                                                                                                                                               
        }                                 
        return $this->m_document;                                 
    }                                 
    function invoke_soap($params)                                                                                                                                                                                                                        
    {                                                                                                                                                                                                                         
        if (! ($dom = domxml_open_file( ABSROOT . $this->m_address ) ))                                                                                                                                                                                                                                                                                                                                                 
        {                                                                                                                                                                               
            $this->error_msg = "File " . $this->m_address . " was not found";                                                                                                                                                                                              
            return false;                                                                                                                                                                                                                               
        }                                                                                                                                    
        $query_action   = "//*[local-name()='binding'][contains(@name,'Soap')]";                                                                                                                                                                                                               
        $query_action  .= "/*[local-name()='operation'][@name='" . $this->operation . "']";                                                                                                                                                                                               
        $query_action  .= "/*[local-name()='operation']";                                                                                                                                                                                               
        $x_action = select_single_node ($dom, $query_action);                                                                                                                                                                                                         
        if (! $x_action)                                                                                                                                                                                                     
        {                                                                                                                                                                                             
            $this->error_msg = "Could not find soap action for " . $this->operation;                                                                                                                                                                                              
            return false;                                                                                                                                                                                              
        }                                                                                                                                                                                                           
        $input='';                                                                                                                                                                                                                                                               
        $input.='<'.'?xml version="1.0" encoding="utf-8"?'.'>';                                                                                                                                                                                                                                                               
        $input.='<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">';                                                                                                                                                                                                                                                               
        $input.='<soap:Body>';                                                                                                                                                                                                                                                               
        $input.='<' . $this->operation . ' xmlns="' . $this->namespace . '">';                                                                                                                                                                                                                                                               
        while (list($name,$value)=each ($params))                                                                                                                                                                                                                                                               
        {                                                                                                                                                                                                                                                               
            if ($name!='Invoke' && $name!='Endpoint' && $name!='Namespace' ) $input.='<' . $name . '><![CDATA[' . $value . ']]></' . $name . '>';                                                                                                                                                                                                                                                               
        }                                                                                                                                                                                                                                                                
        $input.='</' . $this->operation . '>';                                                                                                                                                                                                                                                               
        $input.='</soap:Body>';                                                                                                                                                                                                                                                               
        $input.='</soap:Envelope>';                                                                                                                                                                                                                                                          
        for ($e=0;$e<2;$e++) $this->endpoint = substr($this->endpoint,strpos ($this->endpoint,'/')+1);                                                                                                                                                                                                                                                       
        $port = "80";                                                                                                                                                                                                                                                    
        $domain = substr($this->endpoint, 0, strpos($this->endpoint,'/'));                                                                                                                                                                                                                                                    
        $address = substr($this->endpoint, strpos($this->endpoint,'/'));                                                                                                
        $this->content_type="text/xml";      
        if (substr($domain,":")!==false)   
        {   
           $domain=explode(":",$domain);   
           $port=$domain[1];   
           $domain=$domain[0];   
        }   
        echo "<!--" . "\n" . $input . "\n" . $domain  . "\n" . $port . "\n" . $address . "-->";                                                                                                                                                                                                          
        return connect($input, $domain, $address, $x_action->get_attribute ("soapAction"), $port);                                                                                                                                                                                                                       
    }                                                                                                                                                                                                                        

    function location()                                                                                                                                                                                                                        
    {                                                                                                                                                                                                                        
        return str_replace ('.wsdl','.jazz', $this->m_address);                                                                                                                                                                                                                        
    }                                                                                                                                                                                                                        

    function render()                                                                                                                                                                                                                        
    {                                                                                                                                                                                                                          
        if (! ($dom = domxml_open_file( ABSROOT . $this->m_address ) ))                                                                                                                                                                                                                                                                                                                                                 
        {                                                                                                                                                                               
            $dom=domxml_new_doc("1.0");                                                                                                
            $jazz=$dom->create_element ("jazz");                                                                       
            $dom->append_child ($jazz);                                     
            $dh   = opendir( "./wsdl" ) or die ("couldn't open directory");                                                                      
            while (! ( ( $file = readdir ( $dh ) ) == false ) )                                                                      
            {                                                                     
                $fullpath = realpath("wsdl/$file");                                                                      
                if (preg_match('/\.(wsdl)$/',$file))                                                                     
                {                                                                                                                                                                                                                           
                    if ($wsdl = domxml_open_file( $fullpath ) )                                                                                                                                                                                                                                                                                                                                                 
                    {                                                                                                                                                                                            
                        $x_service = select_single_node ($wsdl, "//*[local-name()='service']");                                                                 
                        if ($x_service)                                                                
                        {                                                                     
                            $filesize  = filesize($fullpath);                                                                        
                            $filedate  = date("F d Y h:i:s A", filemtime ($fullpath));                                                                       
                            $x_file=$dom->create_element ("file");                                                               
                            $x_file->set_attribute ("title",$x_service->get_attribute ("name"));                                                                  
                            $x_file->set_attribute ("name",$file);                                                                  
                            $x_file->set_attribute ("size",$filesize);                                                                  
                            $x_file->set_attribute ("path","wsdl/" . str_replace('.wsdl','.jazz',$file));                                                                                     
                            $x_file->set_attribute ("date",$filedate);                                                                                     
                            $jazz->append_child($x_file);                                                               
                        }                                                                                                                                                                                                                   
                    }                                                                             
                }                                                                         
            }                                                                     
            closedir( $dh );                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                 
        $root=$dom->document_element();                                                                                                                                                                                                             
        $mask=MAINTRANSFORMER;                                                                                                                                                                                                                                       
        if ($this->operation=="__invoke__")                                                                                                                                                                                                                                       
        { # apply EXPORT TRANSFORMATION                                                                                                                                                                                                                                      
            $this->content_type="text/plain";                                                                                                                                                                                                                                    
            $mask=$this->m_wardrobe[$this->element . $this->operation]["path"];                                                                                                                                                                                                                                       
        }                                                                                                                                                                              
        while (list ($name,$value)=each ($this->m_wardrobe))                                                                                                                                                                    
        {                                                                                   
            $x_mask=$dom->create_element ("mask");                                                                                      
            $root->append_child($x_mask);                                                                                                                                                                          
            while (list ($prop_name,$prop_value)=each ($value))                                                                                                                                                                    
            {                                                                                   
                $x_mask->set_attribute ($prop_name,$prop_value);                                                                                                                                                                                                                      
            }                                                                                                                                                                                                                    
        }                                                                     
        $output=apply_dom ($dom, $mask, $this->location(), $this->operation, $this->element);                                                           
        ##highlight_string($output);              
        #exit;                                                                                                                                                                       
        return $output;                                                                                                                                                                                                                          
    }                                                                                                                                                                                                                        
}                                                                                                                                                                                                                  

function page_onload ()                                                                                                                                                                                                           
{                                                                                                                                                                                                           
    $dir       = NULL;                                                                                                                                                                                                                                                       
    $jazz      = NULL;                                                                                                                                                                                                                                                       
    $operation = NULL;                                                                                                                                                                                                                                                       
    $element   = NULL;                                                                                                                                                                                                                                                       
    $file      = NULL;                                                                                                                                                                                                                                                       
    $action    = NULL;                                                                                                                                                                                                                                                       
    $path      = array();       

  
	$o = $_SERVER['REQUEST_URI'];   //$_GET["o"]       
	while (substr($o,0,1)=='/') $o=substr($o,1);  # echo $o;                                                                                                                                                                                                          
	$items=explode ('/', $o);    
	         
	# The  first  thing  that  we do is look at the URL to determine what action                                                                                                                                                                                                                                                        
    foreach ($items as $item) # is  being  requested.  This page is navigated to                                                                                                                                                                                                                                                      
    { # from  a .HTACCESS  file  so  that the URL should always be in the format                                                                                                                                                                                                                                           
        if (strpos($item,'.jazz')!==false) # PATH_TO_FILE/OPERATION/PARAM/ACTION                                                                                                                                                                                                                                                      
        { # with  PATH_TO_FILE  being  determined  by the presence of the string                                                                                                                                                                                                                                                   
            $dir=implode ('/', $path) . '/' . $item;# '.jazz' in that portion of                                                                                                                                                                                                                                                      
        } # the  URL.  By  splitting  the entire URL by '/' we can loop thru the                                                                                                                                                                                                                                                       
        else if ($element) $action=$item; # items  in  the  array and parse each                                                                                                                                                                                                                                              
        else if ($operation) $element=$item; #  string.  After  the PATH_TO_FILE                                                                                                                                                                                                                         
        else if ($dir)  $operation=$item; # parameter  has  been  found the next                                                                                                                                                                                                                     
        else $path[]=$item; # string  in  the  list  is  the OPERATION, then the                                                                                                                                                       
    } # ELEMENT and ACTION variables  are  read  from  the  array in that order.         
	
//	echo $dir . '<br>';                                                                                                                                                                                                                                                   
    $file=str_replace ('.jazz', '.wsdl', $dir); # load PATH_TO_WSDL from PATH_TO_PAGE   
	       
//	  echo 'file: ' . $file . '<br>';                                                       
//    echo 'action: ' . $action . '<br>';                                                       
//    echo 'element: ' . $element . '<br>';                                                       
//    echo 'operation: ' . $operation . '<br>';                                                 
//    echo 'path: ' . implode('--',$path) . '<br>';            
                                           
    if (strlen($_POST["WSDLCopy"]) > 0)                                                                                                                                                                                                                                                               
    { # INVOKE SOAP METHOD from POST variables                                                                       
        $upload_name = $_POST["WSDLCopy"];                                                                                                                                                                                                                       
        $wsdl=implode('',file($upload_name));                                                                                                                                                                                                                     
        if (! ($svc = domxml_open_mem( $wsdl ) ))                                                                                                                                                                                                                                                                                                                                                 
        {                                                                                                                                                                               
            echo "File " . $upload_name . " is not well-formed XML.";                                                                                                                                                                                              
        }                                            
        else if (preg_match('/\/(\w+)\.(asmx|wsdl)/i',$upload_name,$header))                                          
        {           
            $query_import = "//*[local-name()='import']";        
            $upload_url=explode ('/',$upload_name);        
            array_pop ($upload_url);        
            $upload_url=implode ('/',$upload_url);        
            foreach (select_nodes($svc,$query_import) as $x_import)        
            {        
                $papa=$x_import->parent_node();        
                $import_url=$upload_url.'/'.$x_import->get_attribute ("schemaLocation");        
                $import_wsdl=implode('',file($import_url));                                                                                                                                                                                                                    
                if (! ($imp = domxml_open_mem( $import_wsdl ) ))                                                                                                                                                                                                                                                                                                                                                 
                {                                                                                                                                                                               
                    echo "File " . $import_url . " is not well-formed XML.";               
                    exit;                                                                                                                                                                                       
                }        
                $copy=$imp->document_element();        
                $copy=$copy->clone_node(true);        
                $copy->insert_before ($copy, $papa);        
                $papa->unlink_node();        
            }                                       
            $tmp = realpath (".") . "/wsdl/". $header[1] . ".wsdl";                                      
            $svc->dump_file ($tmp);                                           
            $href=str_replace (ABSROOT,WEBROOT,$tmp);                                                                
            $href=str_replace ('.wsdl','.jazz',$href);                                                                                                        
            echo "<script>location.href='" . $href . "';</script>";                                                              
        }   else echo $upload_name . " could not be parsed for a filename.";                                         
        exit;                                                                                                                                                                                                                                          
    }                                                                                                                                                                                                                                                 
    foreach( $_FILES as $file_name => $file_array )                                                                            
    {                                                                             
        $upload_path = $file_array['tmp_name'];                                                                           
        $upload_name = $file_array['name'];                                                                           
        $upload_type = $file_array['type'];                                                                           
        $upload_size = $file_array['size'];                                                                           
        if ( is_uploaded_file( $upload_path )  )                                                                            
        {                                                                           
            $tmp = realpath (".") . "/wsdl/". $upload_name;                                                                           
            copy($upload_path, $tmp) or die("unable to create info" . $tmp . realpath ("."));                                                                
            $href=str_replace (ABSROOT,WEBROOT,$tmp);                                                                
            $href=str_replace ('.wsdl','.jazz',$href);                                                                                                        
            echo "<script>location.href='" . $href . "';</script>";                                                              
            exit;                                                                        
        }                                                                             
    }                                                            

    $webservice = new wsdl ($file);                                                                                                                                                                                                                    
    $webservice->operation=$operation;                                                                                                                                                                                                                    
    $webservice->element=$element;                                                                                                                                                                                                                                                             
    $webservice->namespace = $_POST["Namespace"];                                                                                                                                                                                                                                                      
    $webservice->endpoint  = $_POST["Endpoint"];                                                                                                                                                                                                               
                                                                                                                                                                                                                  
    if (strlen($_POST["Invoke"]) > 0)                                                                                                                                                                                                                                                               
    { # INVOKE SOAP METHOD from POST variables                                                                                                                                                                                                                        
        $output = $webservice->invoke_soap ($_POST);                                                                                                                                                                                                                                                 
    }                                                                                                                                                                                                             
    else if (strlen($_POST["SaveArgument"]) > 0)                                                                                                                                                                                                                                                               
    {                                                                                                                                                                                                                                                               
        $output = $webservice->save_param ($operation, $_POST["ArgumentName"], $_POST["ArgumentType"], isset($_POST["ArgumentIsArray"]));                                                                                                                                  
        $href='/'.$dir.'/'.$operation;                                                                                                         
        echo $output ? "<script>location.href='" . $href . "';</script>" : $webservice->error_msg;                                                                                                                                                                                       
        exit;                                                                                                                                                                                                                                           
    }                                                                                                                                                                                                              
    else if (strlen($_POST["SaveMethod"]) > 0)                                                                                                                                                                                                                                                               
    {                                
        if ($_POST["MethodMemberType"]==0)                     
        {                                                                                                                                                                                                                                             
            $output = $webservice->save_method( $_POST["MethodName"], $_POST["MethodType"], isset($_POST["MethodIsArray"]));                                                                                                                                                                                          
            $href='/'.$dir.'/'.$_POST["MethodName"];                       
        }                     
        else                     
        {                                                                                                                                                                                                                                             
            $output = $webservice->save_datatype($_POST["MethodName"], $_POST["MethodMemberType"]==1);                                                                                                                                                                                          
            $href='/'.$dir.'/'.$_POST["MethodName"].'/struct';                       
        }                                                                                                                                 
        echo $output ? "<script>location.href='" . $href . "';</script>" : $webservice->error_msg;                                                                                                                                                                                       
        exit;                                                                                                                                                                                                                                           
    }                                                                                                                                                                                                             
    else if (strlen($_POST["SaveEnum"]) > 0)                                                                                                                                                                                                                                                               
    {                                                                                                                                                                    
        $output = $webservice->save_datamember($operation, $_POST["EnumName"]);                                                                                                                                                           
        $href='/'.$dir.'/'.$operation.'/enum';                       
        echo $output ? "<script>location.href='" . $href . "';</script>" : $webservice->error_msg;                                                                                                                                                                                       
        exit;                                                                                                                                                                                                                                        
    }                                                                                                                                                                                                             
    else if (strlen($_POST["SaveMember"]) > 0)                                                                                                                                                                                                                                                               
    {                                                                                                                                                                     
        $output = $webservice->save_datamember($operation, $_POST["MemberName"], $_POST["MemberType"], isset($_POST["MemberIsArray"]));                                                                                                                                                           
        $href='/'.$dir.'/'.$operation.'/struct';                       
        echo $output ? "<script>location.href='" . $href . "';</script>" : $webservice->error_msg;                                                                                                                                                                                       
        exit;                                                                                                                                                                                                                          
    }                                                                                                                                                                                                             
    else if (strlen($_POST["CreateClass"]) > 0)                                                                                                                                                                                                                                                               
    {                                                                          
        $webservice = new wsdl ();                                                                                                               
        $output = $webservice->save_webservice($_POST["ClassName"], $_POST["ClassAddress"], $_POST["ClassNamespace"], $_POST["ClassPrefix"]);                                                                                                                                                                                                                 
        $href='/'.str_replace ('.wsdl', '.jazz', $webservice->m_address);     
		
//		$tmp = str_replace (WEBROOT, ABSROOT, $_POST["ClassAddress"]);
//		
//		if (file_exists($tmp)) $scriptdata = fread(fopen($tmp, "r"), filesize($tmp));
//		
//		
//		
//		if (strlen($scriptdata) > 0)
//		{
//		    $pattern = '/function\s+(.*)\((.*)\)/';
//			if (preg_match_all ($pattern, $scriptdata, $result))
//			{
//	             print_r ($result);
//			     for ($e=0;$e<sizeof ($result[1]);$e++)
//				 {
//				     $method    = trim($result[1][$e]);
//					 $arguments = explode(',', trim($result[2][$e])); 
//					 $type      = 's:int'; # auto-gen functions return INT by default
//				     echo "Saving method $method, $type, false <br>";
//					 $output    = $webservice->save_method( $method, $type, false );                                                                                                                                                                                                                    
//					 $webservice->operation=$method;     
//				     echo "arguments; $arguments <br>"; 
//					 for ($x=0;$x<sizeof ($arguments);$x++)
//					 {
//                       $argument = trim(str_replace('$','',$arguments[$x]));
//					     if (strlen($argument) > 0)
//						 {
//							 $type = 's:string'; # auto-gen arguments are STRING by default
//							 if (strpos($argument,'=')!==false)
//							 { # if there is a default value use it to determine argument type
//								 $array    = explode ('=', $argument);
//								 $argument = $array[0];
//								 if (is_numeric ( $array[1] )) $type='s:int';
//							 }
//							 echo "Saving argument $method, $argument, $type, false <br>";
//							 $output   = $webservice->save_param ( $method, $argument, $type, false );      
//						 }    
//					 }  
//				 }
//			}
//		if (strlen($webservice->error_msg) > 0)
//		{
//		   echo $webservice->error_msg;
//		   
//		}
//		     exit;
//		}
//		# echo 'No script data in "'.$tmp.'"';      
//		#    exit;    
		
		
		                                                                                                                                         
        echo $output ? "<script>location.href='" . $href . "';</script>" : $webservice->error_msg;                                                                                                                                                                                       
        exit;                                                                                                                                                                                                                                           
    }                                                                                                                                                                                                          
    else if (strlen($_POST["SaveClass"]) > 0)                                                                                                                                                                                                                                                               
    {                                                                                                                                                                 
        $output = $webservice->save_webservice($_POST["ClassName"], $_POST["ClassAddress"], $_POST["ClassNamespace"], $_POST["ClassPrefix"]);                                                                                                                                                           
        $href='/'.str_replace ('.wsdl','.jazz',$webservice->m_address);                                                                                                                                                         
        echo $output ? "<script>location.href='" . $href . "';</script>" : $webservice->error_msg;                                                                                                                                                                                       
        exit;                                                                                                                                                                                                                                           
    }                                                                                                                                                                                                         
    else if ($element=="__remove_type__")                                                                                                                                                                                                                                                               
    {                                                                                                                                                                 
        $output = $webservice->remove_datatype($operation);                                                                                                                                                           
        $href='/'.$dir;                                                                                                                                  
        echo $output ? "<script>location.href='" . $href . "';</script>" : $webservice->error_msg;                                                                                                                                                                                       
        exit;                                                                                                                                                                                                                                           
    }                                                                                                                                                                                                        
    else if ($element=="__remove__")                                                                                                                                                                                                                                                               
    {                                                                                                                                                                 
        $output = $webservice->remove_method($operation);                                                                                                                                                           
        $href='/'.$dir;                                                                                                                                  
        echo $output ? "<script>location.href='" . $href . "';</script>" : $webservice->error_msg;                                                                                                                                                                                       
        exit;                                                                                                                                                                                                                                           
    }                                                                                                                                                                                                         
    else if ($action=="__remove_enum__")                                                                                                                                                                                                                                                               
    {                                                                                                                                                                 
        $output = $webservice->remove_datamember($operation, $element);                                                                                                                                                           
        $href='/'.$dir.'/'.$operation.'/struct';                                                                                                                                  
        echo $output ? "<script>location.href='" . $href . "';</script>" : $webservice->error_msg;                                                                                                                                                                                       
        exit;                                                                                                                                                                                                                                           
    }                                                                                                                                                                                                           
    else if ($action=="remove")                                                                                                                                                                                                                                                               
    {                                                                                                                                                                 
        $output = $webservice->remove_param($operation, $element);                                                                                                                                                           
        $href='/'.$dir.'/'.$operation;                                                                                                                                  
        echo $output ? "<script>location.href='" . $href . "';</script>" : $webservice->error_msg;                                                                                                                                                                                       
        exit;                                                                                                                                                                                                                                           
    }                                                                                                                                                                                                           
    else                                                                                                                                                                                                          
    {                                                                                                                                                                                                                                     
        $output = $webservice->render ();                                                                                                                                                                                                            
    }                                                                                                                                                                                                           
    header ("Content-Type: " . $webservice->content_type);                                                                                                                                                                                                                   
    echo  $output ? $output : $webservice->error_msg;                                                                                                                                                                                                                
    exit;                                                                                                                                                                                                           
}                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                      
                                                                                                                                                                                                            

# HELPER FUNCTIONS                                                                                                                                                                                                                                  
# ============================================================================                                                                                                                                                                                                                                  
function sendToPHPDc ($host,$method,$path,$data,$useragent=NULL,$action=NULL,$port=80) {                                                                                                                                                                                                                                                
    if (empty($method)) {                                                                                                                                                                                                                                                
        $method = 'GET';                                                                                                                                                                                                                                                
    }          
    if (empty($port)) {
        $port = '80';
    }
    echo "\n<!--" . $port . "-->";                                                                                                                                                                                                                                       
    $method = strtoupper($method);                                                                                                                                                                                                                                                
    $fp = fsockopen($host,$port);                                                                                                                                                                                                                                                
    if ($fp) {                                                                                                                                                                                                                                                
        if ($method == 'GET') {                                                                                                                                                                                                                                                
            $path .= '?' . $data;                                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                
        fputs($fp, "$method $path HTTP/1.0\r\n");                                                                                                                                                                                                                                                
        fputs($fp, "Host: $host\r\n");                                                                                                                                                                                                                                                
        fputs($fp, "Content-type: text/xml\r\n");                                                                                                                                                                                                                                                
        fputs($fp, "Content-length: " . strlen($data) . "\r\n");                                                                                                                                                                                                                                                
        if ($useragent)                                                                                                                                                                                                                                                
            fputs($fp, "User-Agent: MSIE\r\n");                                                                                                                                                                                                                                                
        if ($action)                                                                                                                                                                                                                                                
            fputs($fp, "SOAPAction: " . $action . "\r\n");                                                                                                                                                                                                                                                
        fputs($fp, "Connection: close\r\n\r\n");                                                                                                                                                                                                                                                
        if ($method == 'POST') {                                                                                                                                                                                                                                                
            fputs($fp, $data);                                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                
        while (!feof($fp))                                                                                                                                                                                                                                                
            $buf .= fgets($fp,1024);                                                                                                                                                                                                                                                
        fclose($fp);                                                                                                                                                                                                                                                
    }                                                                                                                                                                                                                                                
    $p = strpos ( $buf, "<");                                                                                                                                                                                                                                                
    $buf = substr($buf, $p);                                                                                                                                                                                                                                                
    return $buf;                                                                                                                                                                                                                                                
}                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                 
function connect($data, $domain, $url,$action, $port=80)                                                                                                                                                                                                           
{                                                                                                                                                                                                                                                
    return sendToPHPDc ($domain, "POST", $url, $data, 0, $action, $port);                                                                                                                                                                                                                                                 
}                                                                                                                                                                                                                                                 

function apply_dom ($dom ,$transformer,$path,$method,$argument)                                                                                                                                                                                                                                                                                                                                                                                                                          
{                                                                                                                                                                                                                                                        
    $params = array("path"=>$path, "method"=>$method, "argument"=>$argument);                                                                                                                                                                                                                                                                                                                                                                                                                          
    $text   = implode ( '', file( $transformer ) );                                                                                                                                                                                                                                                                                                                                                                             
    if ($xsl = domxml_xslt_stylesheet ($text))                                                                                                                                                                                                                                                                                                                                                                                                                                 
    {                                                                                                                                                                                                                                                                                                                                                                                                                            
        if ($result = $xsl->process($dom, $params))                                                                                                                                                                                                                                                                                                                                                                                                                                 
        { return   $xsl->result_dump_mem($result) ;                                                                                                                                                                                                                                                                                                                                                                                                                                  
        } else echo "<h2>Sorry</h2><hr>Path " . $transformer . " failed to transform. Please try again later.";                                                                                                                                                                                                                                                                                                                                                                                                                                 
    } else echo "<h2>Sorry</h2><hr>XSL did not load from $transformer. Please try again later. ";                                                                                                                                                                                                                                                                                                                                                                                                                            
    return false;                                                                                                                                                                                                                                         
}                                                                                                                                                                                                                                                 

function apply ($source,$transformer,$path,$method,$argument)                                                                                                                                                                                                                                                                                                                                                                                                                          
{                                                                                                                                                                                                                                                                 
    if ($dom = domxml_open_file( $source ))                                                                                                                                                                                                                                                                                                                                                 
    { return apply_dom ($dom ,$transformer,$path,$method,$argument);                                                                                                                                                                                                                                                                                                                                                                                                                             
    } else echo "XML did not load from $source. Please try again later.";                                                                                                                                                                                                                                                                                                                                                                                                                          
    return false;                                                                                                                                                                                                                                                                                                                                                                                                                         
}                                                                                                                                                                                                                                                                                                                                                                                                               

function select_single_node($node, $value) // select_single_node                                                                                                                                                                                                                                                                                                                                                               
{                                                                                                                                                                                                                                                                                                                                                                  
    $xpath = xpath_new_context($node);                                                                                                                                                                                                                                                                                                                                                               
    $xnode = xpath_eval($xpath, $value);                                                                                                                                                                                                                                                                                                                                                                
    foreach ($xnode->nodeset as $node) return $node;                                                                                                                                                                                                                                                                                                                 
    return false;                                                                                                                                                                                                                                                                                                                                                                 
} // select_single_node                                                                                                                                                                                                                                                                                                                                                               

function select_nodes($node, $value) // select_nodes                                                                                                                                                                                                                                                                                                                                                               
{                                                                                                                                                                                                                                                                                                                                                                  
    $xpath = xpath_new_context($node);                                                                                                                                                                                                                                                                                                                                                               
    $xnode = xpath_eval($xpath, $value);                                                                                                                                                                                                                                                                                                                                                                 
    return $xnode->nodeset;                                                                                                                                                                                                                                                                                                                                                                 
} // select_nodes                                                                                                                                                                                                           
 
page_onload ();                                                                                                                                                                                                           
?>
